viff is a freeware tool for comparing and merging files. It will run on Unix, DOS, and in DOS-boxes under all flavors of Microsoft Windows. It is character based, command line oriented, and keyboard controlled. It was created in january 1994 to allow several programmers on a large software project to work simultaneously on each their copy of the many hundred files of the project by offering a powerful, fast, and solid way to merge their changes. In that and other projects, viff soon became indispensable.
The power of viff is that
This document is the manual for viff. It explains both the options for invoking viff and the commands available inside it.
In program development teams, several programmers work on the same set of source files. There are basically two ways this can be coordinated:
viff was created to support the copy-merge method. It is surely the most convenient method, but the need to merge files has traditionally been a very, very big problem. For instance, an output from the "diff" program can be used as guidance for merging two files and though this is a help, a diff output is hard to read and each difference is presented with no context. It also still requires manual editing, so the merger needs to work with and switch between two files plus a diff output all at the same time.
Anyone who has tried this will know that this is a tiresome and tedious task if there are more than just a couple of changes. Also, the risk of introducing bugs (by mistyping, overlooking a change, changing the code the wrong place, etc) is quite high. If two files alone seems hard to merge this way, merging two whole directories can be practically impossible!
This is where viff comes in. It automates this whole process by running diff on the files, interpret diff's output, and present the differences in a manner suited for easy interactive merging and even editing of the two files. It can viff two entire directories as easy as just two files.
Of course, viff is not only meant for programmers. It is also very useful for diffing and merging HTML web-pages and all other plain texts.
Many window based programs have lots of fancy, irrelevant features, but often very little real power. They are like James Bond's Aston Martin equipped with a lawnmower engine whereas viff is a Range Rover with a Range Rover engine. In that sense viff can be compared to e.g. grep. grep is not a fancy window based program that will highlight every matching line in a file in a scrollable, mouse-operated window with font options in a menubar. No, grep is plain and simple and therefore it is a delight to use it when you really want to get some work done.
When you only have to merge two files you are likely to think to yourself: "I'm glad I can merge the files at all". You might be pleased to use an impressive looking program to merge the two files at your own leisure pace. But, when merging several files -- dozens or hundreds -- it rapidly becomes more and more important to use a tool that solves the problem at hand as fast and smoothly as possible. You are not impressed anymore, you just have a job to do.
viff use diff to perform the actual diffing, and can therefore only compare two files with each other. But unlike diff, viff can make sense of other kind of arguments than just two filenames. These will be described here.
The simplest invocation of viff is
viff file1 file2
viff always start up selecting the changes belonging to the first
file specifed (referred to as "file 1" for short) so it is wise to
specify the more recent file(s) first.
To speed things up, viff will process a whole series of files if
more than two filenames are given and the first or last refers to a
directory. Doing this,
viff file1 file2 tmp
will cause viff to compare file1 and file2 to the corresponding
files in tmp. Placing the directory first (ie viff tmp file1
file2) will reverse the comparison.
As another example, the C-files in two entire directories can be
compared easily using
viff version5/*.c version4
When invoked with two directory names, viff will by itself search the first directory for files. So if you want to compare all the files in the two directories in the example above, you won't even have to specify version5/*, but can simply ask for
viff version5 version4
viff has several options.
The following options can only be used when viffing a set of files:
You can combine options in the standard Unix fashion, like
viff -vlf sved.c *.c ../work
In summary, these are the differences between viffing just two files and viffing a set of files:
binary_ext[]
array in viffutil.c and
recompile viff.
(todo: How are the two files displayed?)
Trailing whitespace is shown as light blue bullets (for space) and diamonds (for tab) on DOS, and as light blue underscores (for both) on Unix. A line exceeding the screen width will end in a small magenta right arrow on DOS and in a magenta > on Unix.
There are two modes in viff: viffmode and editmode. viff always starts up in viffmode and by pressing Insert you can change into editmode and back into viffmode again. Each mode has its own type of status line.
In viffmode the statusline is green and can look like this:
Viff ** password.c 7/13 11-2 (53+7)
The remainer of the line is specific for viffmode:
In editmode the statusline is red and can look like this:
Edit ** password.c col:7 lin:14/18 char= 0xd 13 015 ^M
Here, Edit tells us that we now are in editmode, and the ** password.c is described above. The remainer of the line is specific for editmode:
Use up/down arrow to move to the previous/next diff and home/end to move to the first/last diff. If the platform supports it you can use the Control and Alt keys in conjunction with these navigation keys to only navigate through differences from file 1 or 2: use e.g. ctrl-up to move to the previous diff from file 1, or alt-end to move to the last diff from file 2.
At a diff you may use left/right arrow to choose whether to use the text from file 1 or 2 or press Space to toggle the selection. You can also use the parenthesis '(' and ')' to select all texts from file 1 or 2 respectively.
For more context, use page up/down to move the view a page up or down. This only shifts the view, not the current diff. To bring the current diff into focus again, use '.' (a tribute to NetHack). If the middle line of the current diff is visible the cursor is put there, else it is put in the status line.
ctrl-s and ctrl-r will do a search (described later).
By pressing Insert, you can edit the entire text; see the section on edit commands below. Pressing Escape or Insert again exits edit mode.
Pressing 1 or 2 saves the modified file as either file 1 or file 2 and quits viffing these two files. Pressing 3 saves the modified file into both file 1 and 2. Pressing 4 saves the modified file into a completely new file and clears the modification-flag, but does not quit. Pressing 5 saves all the text exactly as you see it, with viff-inserted lines and delimiters and everything.
Escape or q quits viffing the two files. Capital Q quits viffing any more files as well. If the modification flag is set, you will be asked to confirm your request to quit. When viff is busy viffing files it is possible to interrupt it in this way too. Here Escape and q ask for confirmation, while Q just quits.
Pressing < will go back to the previously viffed pair of files, or re-viff the current file if there are no previous viffings. For symmetry, pressing > will go on to the next pair (like q).
Pressing Insert enters edit mode. The usual arrow movement keys and delete keys apply as well as a few other Emacs-like edit facilities. Use F1 to see them all. Use Escape or Insert to exit.
To copy text, kill it using ctrl-k and yank the text back at the desired position using ctrl-y. To copy several lines, press ctrl-k several times after one another. This is useful for pasting if you don't want just the text from file 1 or just that from file 2, but rather something from both files.
ctrl-s and ctrl-r will do a search.
In viff you can search in all the text, both forward (by pressing ctrl-s) and backward (by pressing ctrl-r) and both in viffmode and in editmode. The search can optionally be case sensitive or be a match on whole words only, which is nice for e.g. locating only occurences of variable "w".
Once you have pressed ctrl-s or ctrl-r, you begin by entering a string to search for. As this string is being entered a match count is shown, helping you to decide when to start the actual search. You can at any time change the search to be case-sensitive (by pressing ctrl-c, for case) and to search for only whole words (by pressing ctrl-w, for word).
The actual search is begun by pressing either ctrl-s or ctrl-r again (or Return), for searching either forward or backward. The cursor then moves to the first match of the search string in the text window in the given direction. Pressing ctrl-s or ctrl-r again will search for the next match. When there are no more matches a beep will sound. Pressing the search key immediately again will wrap and continue searching.
Pressing ctrl-g will quit searchmode and go back to where you were when you started searching. Pressing any other key will shift into editmode and input that key.
The last search string is remembered by viff, so you can repeat a search by pressing the search key twice, e.g. ctrl-s ctrl-s.
viff is based on curses(3)
. The 16-bit MS-DOS version
has been compiled with MSVC and linked with PDcurses v2.2. The 32-bit
version has been compiled with
djgpp.
The 32-bit version is limited only by memory. I have e.g. viffed two
4Mb files with 530,000 lines each and with 175,000 differences without
problems.
Here are a few odds and ends.
header_table[]
in viff.c.
viff was written by Richard Nordsted Flamsholt. I'll be glad to receive comments, bug-reports, ideas and suggestions, and other feedback at richard@native.dk.